package cn.tedu.collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author :Colin
 * @version 创建时间: 2021/6/21 10:39
 */
/*本类用于测试list接口*/
public class
TestList {
    public static void main(String[] args) {
        //1.创建list接口多态对象，注意list是接口
       List<String> list= new ArrayList<>();
       list.add("葫芦娃1");
       list.add("葫芦娃2");
       list.add("葫芦娃3");
       list.add("葫芦娃4");
       list.add("葫芦娃5");
       list.add("葫芦娃6");
       list.add("葫芦娃7");
       System.out.println(list);
       System.out.println(list.contains("葫芦娃1"));
       System.out.println(list.equals("葫芦娃1"));
       System.out.println(list.hashCode());
       System.out.println(list.isEmpty());
       System.out.println(list.remove("葫芦娃1"));
       System.out.println(list.size());
       System.out.println(Arrays.toString(list.toArray()));

       list.add("小蝴蝶");
       System.out.println(list);
       list.add(1,"蝎子精");//指定位置添加元素
       System.out.println(list);
       System.out.println(list.get(3));//获取指定位置上的元素
       list.add(3,"小蝴蝶");
       System.out.println(list);
       System.out.println(list.indexOf("小蝴蝶"));//指定元素首次出现下标
       System.out.println(list.lastIndexOf("小蝴蝶"));//指定元素最后一次出现下标
       System.out.println(list);
       System.out.println(list.remove(2));//
       System.out.println(list);
       System.out.println(list.remove("蝎子精"));
       System.out.println(list);
       System.out.println("*****");
       System.out.println(list.set(2,"蝎子精"));//葫芦娃4
       System.out.println("!!!!");
       System.out.println(list);
       List<String> subList =list.subList(3,5);
       System.out.println(subList);
       System.out.println("-------");
       List<String> list2 =new ArrayList();
       list2.add("1");
       list2.add("2");
       list2.add("3");
       System.out.println(list.addAll(list2));
       System.out.println(list);
       System.out.println(list.addAll(0,list2));
       System.out.println(list);
       System.out.println(list.containsAll(list2));
       System.out.println(list.contains(list2));
       list.removeAll(list2);
       System.out.println(list);

    }
}
